package com.study.javaOther.spel;

import com.alibaba.fastjson.JSONObject;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import java.util.Arrays;


public class MainTest {
    public static void main(String[] args) throws ClassNotFoundException {
//        User resource = new User();
//        JSONObject subject = new JSONObject();
//        subject.put("name", "ws");
//        resource.setName("([.]*)");
//        String action="write";
//        Context cxt = new Context(subject, resource, action);
//        ExpressionParser exp = new SpelExpressionParser();
//        Expression rule=exp.parseExpression("subject['name'] matches resource.name");
//        System.out.println("rule.getValue(cxt, Boolean.class) = " + rule.getValue(cxt, Boolean.class));

        String[] split = "#com.study.javaOther.spel.User.print('123','456')".split("#");

        ExpressionParser parser = new SpelExpressionParser();
//        Expression expression = parser.parseExpression("T(com.study.javaOther.spel.User).print('123','456')");
        Expression expression = parser.parseExpression("new com.study.javaOther.spel.User().print('123','456')");
        StandardEvaluationContext ctx = new StandardEvaluationContext();




        // 设置需要执行方法的类
//        ctx.setRootObject(Class.forName(split[0]));
//        ctx.
        System.out.println("expression.getValue(ctx, Object.class) = " + expression.getValue(ctx, Object.class));
    }
}
